package org.potomak.patientmanager.application;

import java.sql.Time;
import java.sql.Date;
import java.util.Set;
import java.util.Iterator;

import org.potomak.patientmanager.beans.model.PatientBean;
import org.potomak.patientmanager.beans.model.AttachmentBean;
import org.potomak.patientmanager.gui.Contacts;
import org.potomak.patientmanager.persistence.JPoxJDO;

public class PatientApplication {

	public static void main(String[] args) {
		String password = "12345678901234567";
		JPoxJDO jpoxJDO = new JPoxJDO(password);
                
                /*
		PatientBean patientBean = jpoxJDO.getPatient("Giovanni Cappellotto");
		System.out.println("Issuing JPOX queries against the Derby DB, patient_manager");
		System.out.println("***********************************************************");
		System.out.println("Query 1: The PatientBean corresponding to the name 'Giovanni Cappellotto' is: ");
		System.out.println("name: " + patientBean.getName());
		System.out.println("gender: " + patientBean.getGender());
		System.out.println("birthday: " + patientBean.getBirthDay());
		System.out.println("notes: " + patientBean.getNumberOfNotes());
		System.out.println("check up: " + patientBean.getNumberOfCheckUps());
		System.out.println("attachments: " + patientBean.getNumberOfAttachments());
               
		//Set attachments = patientBean.getAttachments();
		//Iterator i = attachments.iterator();
		//while(i.hasNext()) {
		//	AttachmentBean attachment = (AttachmentBean)(i.next());
		//	byte[] blob = attachment.getFile();
		//	for(int j = 0; j < blob.length; j++) {
		//		System.out.print(blob[j]+" ");
		//	}
		//}
		
		System.out.println("***********************************************************");
		System.out.println("Insert 1: Create a new note by calling JPoxJDO.insertNote(patientBean,\"ciao\",\"con\",new Date)");
		int success = jpoxJDO.insertNote(patientBean,"ciao", "con",new Date());
		if (success == 1) {
			System.out.println("Successfully inserted the note 'ciao' into the database.");
		} else {
			System.out.println("Was not successful inserting the note into the database.");
		}
		System.out.println("***********************************************************");
		System.out.println("Insert 2: Create a new patient by calling JPoxJDO.insertPatient(");
		System.out.println("\"Ciao Ciao\", new Date(), \"F\", 1.79, 80, new Date())");
		success = jpoxJDO.insertPatient("Ciao Ciao", new Date(), "F", new Double(1.79), new Double(80.1), new Date());
		if (success == 1) {
			System.out.println("Successfully inserted the patient 'Ciao Ciao' into the database.");
		} else {
			System.out.println("Was not successful inserting the user into the database.");
		}
                */
		System.out.println("***********************************************************");
                System.out.println("Query 2: get all patients");
		PatientBean[] patients = jpoxJDO.patientList();
                System.out.println("Patient list:");
		for(int i = 0; i < patients.length; i++) {
                    System.out.println("patient name: "+patients[i].getName());
                    System.out.println("patient # of check ups: "+patients[i].getNumberOfCheckUps());
                }
		System.out.println("***********************************************************");
                System.out.println("Starting GUI.");
                Contacts frame = new Contacts(jpoxJDO,patients);
                frame.setVisible(true);
                System.out.println("***********************************************************");
	}

}
